package com.tide.crm.controller;

import java.io.IOException;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.tide.crm.annotation.LogAnnotation;
import com.tide.crm.model.ConvergeAttachment;
import com.tide.crm.service.ConvergeAttachmentService;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/upload")
public class UploadController {

	protected Logger logger = LoggerFactory.getLogger(getClass());
	
	@Resource(name="convergeAttachmentService")
	private ConvergeAttachmentService convergeAttachmentService;
	
	@Value("${uploadFile.qualification}")
	private String qualification;
	@Value("${uploadFile.goodPath}")
	private String goods;
	
	@LogAnnotation
	@PostMapping(value = "/execute/{type}")
	@ApiOperation(value = "文件上传")
	public ConvergeAttachment uploadFile(MultipartFile file,@PathVariable int type) throws IOException {
		String filePath = null;
		if(type == 1) {
			//说明是企业认证信息上传图片
			filePath = qualification;
		}else if(type ==2) {
			//说明是商品信息上传图片
			filePath = goods;
		}
		return convergeAttachmentService.saveAttachment(file,filePath);
	}
	
	
}

